capture log close
log using suic-econ-a8-period.txt, replace text

//  program:    suic-econ-a8-period.do
//  task:		sensitivity analyses for recessions on suicide: by period
// 	input:		suic-econ-data1-census.dta
//	output:		suic-econ-atable-time-icei.txt suic-econ-atable-time-unemp.txt
//  project:    economic conditions and suicide
//  author:     sam harper \ 17dec2014

//  #0
//  program setup

version 12
set linesize 80
clear all
macro drop _all
set matsize 11000


// #1
// data and descriptive table

use suic-econ-data1-census, clear

* re-scale icei for a 10-unit change, change sign to estimate decrease
replace icei= -1*icei/10

// #2
// basic FE model variations by period

forvalues i=1980(5)2005 {
	
	disp "Period: `i'-2010"
	* using ICEI as exposure
	qui poisson suic icei i.sex i.race2 i.agecat i.stabb ///
	i.season##i.year if year>=`i', ///
	offset(logpop100y) vce(cluster stabb) nolog irr cformat(%4.3f)

	* predicted marginal effects
	eststo m_i`i': estpost margins, dydx(icei) predict(ir) ///
	vce(unconditional) cformat(%4.2f)
	
	* now for unemployment as exposure
	qui poisson suic unemprtsa i.sex i.race2 i.agecat i.stabb ///
	i.season##i.year if year>=`i', ///
	offset(logpop100y) vce(cluster stabb) nolog irr cformat(%4.3f)

	* predicted marginal effects
	eststo m_u`i': estpost margins, at(unemprtsa=(5.8 9.6)) predict(ir) ///
	contrast(atcontrast(r._at)) vce(unconditional) cformat(%4.2f)
	}
	
	
// write results for ICEI and unemployment to file

esttab m_i* using suic-econ-atable-time-icei.txt,  ///
	cells("b(fmt(%4.2f)) ci(par( ( , ) ))") collabels(Est. 95%CI) nostar not ///
	nolines nonum mtitle((0) (1) (2) (3) (4) (5)) delimiter(";") replace

esttab m_u* using suic-econ-atable-time-unemp.txt,  ///
	cells("b(fmt(%4.2f)) ci(par( ( , ) ))") collabels(Est. 95%CI) nostar not ///
	nolines nonum mtitle((0) (1) (2) (3) (4) (5)) delimiter(";") replace
	
log close
exit	
